"""
頁面的字段的組成是由：
1. 報表的配置
2. 額外添加的字段合成 （ex：日期、時段等等）
{"key": "2001", "value": "牛牛分析"},
{"key": "2002", "value": "转转分析"},
{"key": "2003", "value": "水果机分析"},
{'key': "2004", "value": "电玩城统计"}
"""
from event_rule.cp.product_event_rule.game_aggregate_report import GAME_AGGREGATE_REPORT
from event_rule.cp.product_event_rule.dwc_bet_user_analysis import DWC_BET_USER_ANALYSIS_CONFIG
from event_rule.cp.product_event_rule.lottery_bet_user_analysis import LOTTERY_BET_USER_ANALYSIS_CONFIG
from common.es_core import report_creator


def _get_game_aggregate_analysis_key_mapper():
    additional_key_mapper = [
        {"key": "day", "name": "日期"},
        {'key': "game_name", "name": "游戏名称"},
    ]
    key_mapper = report_creator.get_key_mapper_list(GAME_AGGREGATE_REPORT.get('values'))
    key_mapper = additional_key_mapper + key_mapper
    return key_mapper


def _get_bet_user_analysis_key_mapper(game_id='lottery'):
    if game_id == 'dwc':
        config = DWC_BET_USER_ANALYSIS_CONFIG
    else:
        config = LOTTERY_BET_USER_ANALYSIS_CONFIG
    key_mapper_dct = report_creator.get_key_mapper_list(config.get('values'))
    return [{'key': '_user_id', 'name': "用户ID"},
            {'key': 'registered_at', 'name': '注册时间'},
            {'key': 'chn', 'name': '渠道'},
            {'key': "room_name", "name": "游戏名称"}] + key_mapper_dct


KEY_MAPPER_FUNC = {
    '2004': _get_game_aggregate_analysis_key_mapper,
    '2005': _get_bet_user_analysis_key_mapper
}


def get_key_mapper(page_id, **kwargs):
    assert page_id in KEY_MAPPER_FUNC
    func = KEY_MAPPER_FUNC.get(page_id)
    key_mapper = func(**kwargs)
    return key_mapper
